package com.fallsvc.re.javasesets.dstackandqueue;

import java.util.Stack;

/**
 * @auther falls_vc
 * description:
 * @date 2025/10/15  8:22
 */
public class Demo1 {
    static class Node{
        public Integer val;
        public Node next;
    }
    // 递归方式
    void printList(Node head){
        if(null != head){
            printList(head.next);
            System.out.print(head.val + " ");
        }
    }
    // 循环方式
    void printList2(Node head) {
        if (null == head) {
            return;
        }
        Stack<Node> s = new Stack<>();
// 将链表中的结点保存在栈中
        Node cur = head;
        while (null != cur) {
            s.push(cur);
            cur = cur.next;
        }
        // 将栈中的元素出栈
        while(!s.empty()){
            System.out.print(s.pop().val + " ");
        }
    }
    public static void main1(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        for (Integer x: stack) {
            System.out.println(x);
        }
        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }
    }

    public static void main(String[] args) {
        System.out.println();
    }
}
